﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using DailyDiet.Services;
using DailyDiet.Services.Constant;
using DailyDiet.util;
using DailyDiet.ViewModels;
using Moq;

namespace DailyDietTest.Helper
{
    public static class InitializeViewModelTestHelper {
        private static InitializeViewModel _initializeViewModel;
        public static async Task<InitializeViewModel> GetInitializeViewModel() {
            if (_initializeViewModel != null) {
                return _initializeViewModel;
            }
            var preferenceMock = new Mock<IPreferenceStorage>();
            preferenceMock.Setup(p => p.Get(TasteSetConstant.SpicyIndexKey, TasteSetConstant.DefaultIndex)).Returns(50);
            preferenceMock.Setup(p => p.Get(TasteSetConstant.SweetIndexKey, TasteSetConstant.DefaultIndex)).Returns(50);
            preferenceMock.Setup(p => p.Get(TasteSetConstant.TasteIndexKey, TasteSetConstant.DefaultIndex)).Returns(50);
            preferenceMock.Setup(p => p.Get(TasteSetConstant.HealthIndexKey, TasteSetConstant.DefaultIndex)).Returns(50);
            var mockedPreference = preferenceMock.Object;

            IDietRecorderStorageService dietRecorderStorageService =
                await DietRecorderStorageServiceTestHelper
                    .GetInitializedDietRecorderStorage();

            IFavoriteStorageService favoriteStorageService =
                await FavoriteStorageServiceHelper.getFavoriteStorage();

            IDietStorageService dietStorageService =
                await DietStorageServiceTestHelper.getIntializedDietStorageService();

            IRecorderStorageFillMeassage recorderStorageFillMeassage =
                new RecorderStorageFillMeassage(dietRecorderStorageService);

            var notificationMock = new Mock<INotificationService>();
            notificationMock
                .Setup(p => p.GetMealTimeByDatetime(It.IsAny<DateTime>()))
                .Returns(GetRecServiceConstant.DINNER);

            INotificationService notificationService = notificationMock.Object;

            ISplitSentenceService splitSentenceService =
                await SplitSentenceServiceTestHelper.GetSplitSentenceService();

            _initializeViewModel = new InitializeViewModel(
                mockedPreference, dietStorageService, favoriteStorageService,
                dietRecorderStorageService, recorderStorageFillMeassage,
                notificationService, splitSentenceService);

            return _initializeViewModel;
        }
    }
}
